<script>

/**
 * Orders Component
 */
export default {
  data() {
    return {
      ordersData: [
        {
          name: "宿迁市民政局",
          domainName: "http://mzj.suqian.gov.cn/",
          seedNum: "3",
          type: "招标",
          collectionNum: "20,021",
          updateTime: "刚刚",
          runningState: "正常"
        },{
          name: "扬州大学附属医院",
          domainName: "http://www.yangzhouyiyuan.com/",
          seedNum: "3",
          type: "招标",
          collectionNum: "43,280",
          updateTime: "刚刚",
          runningState: "异常"
        },{
          name: "镇江市体育局",
          domainName: "http://tyj.zhenjiang.gov.cn/",
          seedNum: "4",
          type: "招标",
          collectionNum: "9,541",
          updateTime: "1分钟前",
          runningState: "停止更新"
        },{
          name: "泰州职业技术学院",
          domainName: "http://www.tzpc.edu.cn/",
          seedNum: "6",
          type: "招标",
          collectionNum: "11,231",
          updateTime: "2分钟前",
          runningState: "正常"
        },{
          name: "江苏省洪泽中学",
          domainName: "http://www.jshzzx.com/",
          seedNum: "8",
          type: "招标",
          collectionNum: "30,001",
          updateTime: "3分钟前",
          runningState: "正常"
        },{
          name: "携程酒店订单",
          domainName: "https://ebooking.ctrip.com",
          seedNum: "21",
          type: "旅游",
          collectionNum: "123,123",
          updateTime: "3分钟前",
          runningState: "正常"
        },{
          name: "生意社",
          domainName: "http://coke.100ppi.com/",
          seedNum: "13",
          type: "财经",
          collectionNum: "3,321",
          updateTime: "3分钟前",
          runningState: "停止更新"
        },{
          name: "我的钢铁",
          domainName: "https://mri.mysteel.com/",
          seedNum: "11",
          type: "行业",
          collectionNum: "2,134",
          updateTime: "3分钟前",
          runningState: "正常"
        },{
          name: "PT塑料网",
          domainName: "https://pt.vogel.com.cn/",
          seedNum: "9",
          type: "行业",
          collectionNum: "1,252",
          updateTime: "5分钟前",
          runningState: "正常"
        },{
          name: "福建省人民政府",
          domainName: "http://fujian.gov.cn",
          seedNum: "21",
          type: "政府",
          collectionNum: "224",
          updateTime: "5分钟前",
          runningState: "正常"
        }
      ],
      totalRows: 100,
      currentPage: 1,
      perPage: 10,
      fields: [
        { key: "name", label: "站点名称" },
        { key: "domainName", label: "站点域名" },
        { key: "seedNum", label: "种子数量" },
        { key: "type", label: "站点类型" },
        { key: "collectionNum", label: "采集数量" },
        { key: "updateTime", label: "最后检测时间" },
        { key: "runningState", label: "运行状态" },
        { key: "viewState", label: "查看状态" },
      ],
      // 采集类型
      reptiletype: [
        {
          name: "全部",
          index: 1,
        },
        {
          name: "手动配置",
          index: 2,
        },
        {
          name: "自动采集",
          index: 3,
        },
        {
          name: "代码采集(xxl-Job)",
          index: 4,
        },
        {
          name: "RPA机器人",
          index: 5,
        },
      ],
      reptileChange: 1,
      //类型筛选
      states: [
        {
          type: "全部",
          index: 1,
        },
        {
          type: "异常",
          index: 2,
        },
        {
          type: "未配置",
          index: 3,
        },
        {
          type: "停止更新",
          index: 4,
        },
        {
          type: "正常",
          index: 5,
        },
      ],
      stateChange: 1,
    };
  },
  watch: {
    "currentPage": {
      handler(){
        console.log("触发更新");
      }
    }
  },
  methods: {
    onFiltered(filteredItems) {
      this.totalRows = filteredItems.length;
      this.currentPage = 1;
    },
    // 种子详情
    seedDetail(row){
      console.log(row);
      this.$router.push('/spider/siteDetail')
    },
    // 采集模板
    toManTem(){
      this.$router.push('/spider/managementTemplate')
    },
    // 创建模板
    toCreateTem(){
      this.$router.push('/spider/createTemplate')
    },
    // 爬虫类型
    reptile(item) {
      this.reptileChange = item.index;
    },
    //类型筛选
    statesItem(item) {
      this.stateChange = item.index;
    },
    journal(item){
      console.log(item);
      this.$router.push("/log")
    },
    datahouse(item){
      console.log(item);
      this.$router.push("/datahouse")
    },
  }
};
</script>

<template>
  <div class="card">
    <div class="card-body pt-0">
      <div class="states-type">
        <span class="type-title">采集类型:</span>
        <button
          type="button"
          class="btn btn-light rounded-pill btn-sm states-type-item"
          :class="{ isActive: reptileChange == item.index }"
          v-for="item in reptiletype"
          :key="item.index"
          @click="reptile(item)"
        >
          {{ item.name }}
        </button>
      </div>
      <div class="states-time">
        <div>
          <span class="time-title">全部状态:</span>
          <button
            type="button"
            class="btn btn-light rounded-pill btn-sm states-time-item"
            :class="{ isActive: stateChange == item.index }"
            v-for="item in states"
            :key="item.index"
            @click="statesItem(item)"
          >
            {{ item.type }}
          </button>
        </div>
      </div>
      <!-- 搜索 -->
      <div class="search-box">
        <div class="position-relative search">
          <input type="text" class="form-control" placeholder="请输入关键字" />
          <i class="mdi mdi-magnify search-icon"></i>
        </div>
      </div>
      <div class="allNum">
        <div class="searchNum">为您检索到<span>5,000+</span>条信息</div>
        <div>
          <b-dropdown dropup variant="secondary" class="butn">
            <template slot="button-content">
              <i class="ri-add-line align-middle" style="font-size: 1rem;"></i>
              <span style="margin:0 20px 0 6px;">采集管理</span>
              <i class="mdi mdi-chevron-up"></i>
            </template>
            <b-dropdown-item-button>添加种子</b-dropdown-item-button>
            <b-dropdown-item-button>错误日志</b-dropdown-item-button>
            <b-dropdown-item-button @click="toCreateTem">添加模板</b-dropdown-item-button>
            <b-dropdown-item-button @click="toManTem">管理模板</b-dropdown-item-button>
            <b-dropdown-item-button>RPA机器人</b-dropdown-item-button>
          </b-dropdown>
        </div>
      </div>
      <div class="table-responsive">
        <b-table
          class="table-centered"
          :items="ordersData"
          :fields="fields"
          responsive="sm"
          :per-page="perPage"
          :current-page="1"
          thead-class="thead-light"
          @filtered="onFiltered"
        >
          <template v-slot:cell(name)="row">
            <span @click="seedDetail(row)" style="color:#5664d2;cursor: pointer;">{{row.value}}</span>
          </template>
          <template v-slot:cell(domainName)="row">
            <a :href="row.value" target="_blank">{{row.value}}</a>
          </template>
          <template v-slot:cell(runningState)="row">
            <div v-if="row.value=='正常'" class="badge font-size-12 badge-soft-success">{{ row.value}}</div>
            <div v-if="row.value=='停止更新'" class="badge font-size-12 badge-soft-warning">{{ row.value}}</div>
            <div v-if="row.value=='异常'" class="badge font-size-12 badge-soft-danger">{{ row.value}}</div>
          </template>
          <template v-slot:cell(viewState)="row">
            <span @click="journal(row.item)" style="cursor: pointer;">日志</span>
            <span style="margin:0 3px;">|</span>
            <span @click="datahouse(row.item)" style="cursor: pointer;">数据</span>
          </template>
        </b-table>
      </div>
      <div class="row">
        <div class="col">
          <div class="dataTables_paginate paging_simple_numbers float-right">
            <ul class="pagination pagination-rounded mb-0">
              <!-- pagination -->
              <b-pagination v-model="currentPage" :total-rows="totalRows" :per-page="perPage"></b-pagination>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.search {
  float: left;
  width: 300px;
}
.butn{
  ::v-deep .btn{
    background-color: #252b3b;
    border-color: #252b3b;
    border-radius: 30px;
    display: flex;
    align-items: center;
  }
  ::v-deep .btn-secondary.focus {
    box-shadow: 0 0 0 0.15rem rgb(37 40 58 / 50%);
  }
}
.search-box{
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.table-centered{
  ::v-deep thead,::v-deep tbody{
    tr{
      th:last-child,td:last-child{
        text-align: right;
      }
    }
  }
}
.allNum{
  padding-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.searchNum{
  span{
    font-size: 1rem;
    color: #3444c1;
    margin: 0 4px;
    font-weight: 600;
  }
}
.isActive {
  color: #fff;
  background-color: #5664d2;
}
.all-products {
  font-size: 15px;
  font-weight: bold;
}
.states-type {
  .type-title {
    display: inline-block;
    color: #74788d;
    padding-right: 10px;
  }
  .states-type-item {
    font-size: 12px;
    margin-left: 10px;
    padding-left: 8px;
    padding-right: 8px;
    min-width: 70px;
    &:hover {
      cursor: pointer;
    }
  }
}
.states-time {
  margin-top: 20px;
  margin-bottom: 20px;
  .ad {
    float: right;
  }
  .time-title {
    display: inline-block;
    color: #74788d;
    padding-right: 10px;
  }
  .states-time-item {
    font-size: 12px;
    margin-left: 10px;
    padding-left: 8px;
    padding-right: 8px;
    min-width: 70px;
    &:hover {
      cursor: pointer;
    }
  }
}
</style>

